package com.doit.day05

import java.io.{FileOutputStream, ObjectOutputStream}
import scala.reflect.io.File

object _05_样例类 {
  def main(args: Array[String]): Unit = {

    val zss1: Phone3 = new Phone3(1, "zss", 18, "male")
    val zss2: Phone3 = new Phone3(1, "zss", 18, "male")
    println(zss1.equals(zss2))//false
    println(zss1.hashCode())
    println(zss2.hashCode())

    println(zss1)

    val stream: ObjectOutputStream = new ObjectOutputStream(new FileOutputStream("D:\\b.txt"))
    stream.writeObject(zss1)//NotSerializableException



    val zss3: Phone4 = Phone4.apply(1, "zss", 18, "male")
    val zss4: Phone4 = Phone4(1, "zss", 18, "male")
    println(zss3.equals(zss4))//true  因为底层给我重写了equals方法
    println(zss3.hashCode())
    println(zss4.hashCode())

    println(zss3)

    stream.writeObject(zss3)



  }
}


class Phone3(val id:Int,val name:String, val age:Int ,val gender:String) extends Serializable



//样例类的成员变量前面可以不加val 默认就是val的
//创建一个对象不用new 代表里面重写了apply方法
//他底层自动给我们重写了伴生类和伴生对象
//还给我们重写了equals方法
//实现了序列化接口
//还给我们重写了hashcode方法
case class Phone4(id:Int,
                  name:String,
                  age:Int ,
                  gender:String)
